home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 14 / 014.d81 / pps #35 < prev    next >
Text File  |  2022-08-26  |  5KB  |  191 lines

  1.  
  2. ======================================
  3.    PEEKs, POKEs, & SYSes -- Part 35
  4.  
  5.        By James Germany Weiler
  6.           and Alien Gardner
  7. ======================================
  8.   Bit-mapped graphics: how to do it
  9. in BASIC.
  10. - - - - - - - - - - - - - - - - - - -
  11.  
  12. A. Setting bit-mapped graphics mode.
  13.  
  14.   This is easy.  Set bit five of
  15.   of the VIC-II control register
  16.   (memory location 53265).  This is
  17.   the bit that determines whether your
  18.   C-64 will display text or bit-mapped
  19.   graphics.  You remember from part 32
  20.   that the value of bit five is 32.
  21.   However, we can't simply poke 32
  22.   into 53265 because the rest of the
  23.   bits in that memory location control
  24.   other functions of the VIC chip,
  25.   including the size and position of
  26.   the screen.  Instead, we PEEK the
  27.   previous value out of 53265,
  28.   logically OR that value with 32,
  29.   and POKE the result back into 53265.
  30.   When you OR two bytes together,
  31.   whatever bits were set in either of
  32.   the original bytes will be set in
  33.   the resulting byte.
  34.  
  35. 10  POKE 53265, PEEK(53625) OR 32
  36.  
  37.   Then decide where in memory your
  38.   bit-map should start.  This is most
  39.   often at memory location 8192.  If
  40.   know how to do bank switching, you
  41.   can put it at 24576.  Bank switching
  42.   is described on pages 101 and 102 of
  43.   the Commodore 64 Programmer's
  44.   Reference Guide.  You can only use
  45.   banks 0 or 1 for high-resolution
  46.   bit-mapped graphics.  Banks 2 and 3
  47.   have ROM where the bit-map would
  48.   go.
  49.     If you want to switch to bank 1,
  50.   POKE 56576,(PEEK(56576)AND 252)OR 2.
  51.   To return to bank 0, POKE 56576,
  52.   (PEEK(56576)AND 252) OR 3.  One
  53.   advantage of bank-switching is
  54.   that you have more memory free for
  55.   your BASIC program.
  56.  
  57.     We use OR again the same way we
  58.   did above so that we set bit three
  59.   without disturbing bits four through
  60.   seven of location 53272.
  61.  
  62. 20  POKE 53272, PEEK(53272) OR 8
  63.  
  64.  
  65. - - - - - - - - - - - - - - - - - - -
  66.  
  67. B. Clearing the bit-mapped screen.
  68.  
  69.   This is easy, too, but time
  70.   consuming.  Just poke zeros into
  71.   the 8000 bytes that make up one
  72.   bit-mapped screen.  Of course, if
  73.   we had bank-switched, we would poke
  74.   the 8000 bytes starting at 24576.
  75.  
  76. 30 FOR C = 8192 TO 8192+8000
  77. 40 POKE C, 0 : NEXT
  78.  
  79.  
  80. - - - - - - - - - - - - - - - - - - -
  81.  
  82. C. Setting the color
  83.  
  84.   This is a lot like clearing the
  85.   bit-mapped screen.  We are limited
  86.   to two colors per block.  Because
  87.   it is simpler to do so, we usually
  88.   choose to make all the blocks the
  89.   same colors.
  90.     The color information for a high
  91.   resolution bit-mapped screen is
  92.   stored in, of all places, the normal
  93.   text screen.  Of course, if you
  94.   bank switch, that won't be the case.
  95.   Then, your color memory will be from
  96.   location 17408 through 18407,
  97.   exactly 16384 bytes (the size of
  98.   one bank) above the normal text
  99.   display.  This is another advantage
  100.   of bank-switching -- you can put
  101.   color on your hi-res screen without
  102.   disturbing your text screen.
  103.  
  104. 50 FOR C = 1024 TO 2023
  105. 60 POKE C, 5 : NEXT
  106.  
  107.   This will produce a green screen
  108.   with black dots when we plot them.
  109.   Bits 0 through 3 of the color bytes
  110.   define the background color.  Bits
  111.   4 through 7 define the color of
  112.   the dots we plot.
  113.  
  114.     You must ensure that neither your
  115.   BASIC program nor its variables use
  116.   any part of the bit-mapped screen
  117.   or color memory.  If your bit-map
  118.   is at 8192, you need to set MEMSIZ
  119.   to 8192.  (POKE 55,0:POKE 56,32)
  120.   If you bank-switch, you can set
  121.   MEMSIZE to 17408, the beginning of
  122.   color memory. (POKE 55,0:POKE 56,68)
  123.  
  124. - - - - - - - - - - - - - - - - - - -
  125.  
  126. D. Plotting
  127.  
  128.   This is by far the hairiest part
  129.   of hi-res bit-mapped graphics.
  130.   To plot a single point, we have to
  131.   determine which bit in which byte
  132.   of the 8000 bytes of the screen
  133.   corresponds to that point.  There
  134.   are 320 dots across and 200 down.
  135.   They are numbered 0 to 319 and 0 to
  136.   199.
  137.  
  138.  
  139. 70 X = 50: Y = 120
  140.  
  141. 80 L=8192 +INT(Y/8)*320 +INT(X/8)*8+(Y
  142. AND7):POKE L,PEEK(L) OR2^(7-(X AND 7))
  143.  
  144.   This will plot a point 50 pixels
  145.   from the left and 120 pixels down.
  146.   Don't worry about understanding
  147.   this formula.  The only thing you
  148.   really need to know is to change
  149.   8192 to 24576 if you are bank-
  150.   switching.  If you really want to
  151.   know what this is all about, try
  152.   wading through pages 121 to 127 in
  153.   the Commodore 64 Programmer's
  154.   Reference Guide.
  155.  
  156.  
  157. - - - - - - - - - - - - - - - - - - -
  158.  
  159. E. Return to the text screen.
  160.  
  161.   This is easy, too.  Just undo what
  162.   you did in step A.  First reset bit
  163.   five of the VIC-II control register
  164.   at 53265.  In Boolean terms (AND,
  165.   OR, and NOT), 223 is the opposite of
  166.   32.  That means that only bit 5 is
  167.   turned off.  When you AND two bytes
  168.   together, whatever bits were set in
  169.   both the original bytes will be set
  170.   in the resulting byte.  ANDing with
  171.   a byte that has only one bit off
  172.   guarantees that that one bit will be
  173.   reset in the result and that all the
  174.   other bits will be untouched.
  175.  
  176. 100 POKE 53265, PEEK(53265) AND 223
  177.  
  178.   And here we use the same technique
  179.   to undo our start-of-bit-map
  180.   selection.
  181.  
  182. 110 POKE 53272, PEEK(53272) AND NOT 8
  183.  
  184.   Finally, if we used bank-switching,
  185.   we have to re-select bank 0, the
  186.   normal bank.
  187.  
  188.   POKE 56576,(PEEK(56576)AND 252)OR 3
  189.  
  190. -------< continued in Part 36 >-------
  191.